package com.zhanggm.s3.user.controller;


import com.bw.springboot.starter.upload.service.FileService;
import com.bw.springboot.starter.upload.util.FileResult;
import com.zhanggm.s3.core.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanggm
 * @since 2021-08-18
 */
@RestController
@RequestMapping("/file/")
public class UploadController {

    @Autowired
    private FileService fileService;


    /**
     * 图片上传
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping("upload")
    public AjaxResult upload(MultipartFile file) throws IOException {
        FileResult fileResult = fileService.upload(file);
        return AjaxResult.success(fileResult);
    }
}
